#include <cstdio>
#include <cstring>
#include <map>
#include <random>
std::mt19937_64 rnd(std::random_device{}());
constexpr int MaxN = 3e1 + 5;
constexpr long long Mod = 998'244'353;
int n;
int p[MaxN];
int a[MaxN];
int k[MaxN];
long long answer;
unsigned long long sha[MaxN];
std::map<unsigned long long, bool> map;
void solve()
{
    unsigned long long ha = 0;
    memset(k, 0, sizeof(k));
    for (int i = 1; i <= n; i++)
    {
        k[i] += p[i] - a[i];
        k[i % n + 1] += a[i];
    }
    long long temp = 1;
    for (int i = 1; i <= n; i++)
    {
        ha += (unsigned long long)(k[i] + 5) * sha[i];
        temp *= k[i];
    }
    if (!map[ha] && temp != 0)
    {
        map[ha] = true;
        answer += temp;
    }
}
void dfs(int u)
{
    if (u > n)
    {
        solve();
        return;
    }
    for (int i = 0; i <= p[u]; i++)
    {
        a[u] = i;
        dfs(u + 1);
    }
}
int main()
{
    freopen("trade.in", "r", stdin);
    freopen("trade.out", "w", stdout);
    scanf("%d", &n);
    long long temp = 1;
    for (int i = 1; i <= n; i++)
    {
        sha[i] = rnd();
        scanf("%d", &p[i]);
        temp *= (p[i] + 1);
    }
    if (temp <= 1e7)
    {
        dfs(1);
        printf("%lld\n", answer);
    }
    else
    {
        bool f = true;
        for (int i = 1; i <= n; i++)
        {
            f &= p[i] != 0;
        }
        printf("%d\n", f ? 1 : 0);
    }
    return 0;
}